<html>
<head>
    <meta charset="utf-8"/>
<meta name="description" content=""/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>docker搭建redis集群(最新修改) | 朱文骁的博客</title>
<link rel="shortcut icon" href="https://lucky-zwx.github.io/favicon.ico?v=1586579434990">
<link href="https://cdn.bootcss.com/font-awesome/5.11.2/css/all.css" rel="stylesheet">
<link rel="stylesheet" href="https://lucky-zwx.github.io/styles/main.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
      integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<script src="https://cdn.bootcss.com/highlight.js/9.15.10/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dart.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/go.min.js"></script>
<script src="https://cdn.bootcss.com/moment.js/2.23.0/moment.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
        integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
        integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
        crossorigin="anonymous"></script>

<!-- DEMO JS -->
<!--<script src="media/scripts/index.js"></script>-->



    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css">
</head>
<body>
<div class="main gt-bg-theme-color-first">
    <nav class="navbar navbar-expand-lg">
    <div class="navbar-brand">
        <img class="user-avatar" src="/images/avatar.png" alt="头像">
        <div class="site-name gt-c-content-color-first">
            朱文骁的博客
        </div>
    </div>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <i class="fas fa-bars gt-c-content-color-first" style="font-size: 18px"></i>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <div class="navbar-nav mr-auto" style="text-align: center">
            
                <div class="nav-item">
                    
                        <a href="/" class="menu gt-a-link">
                            首页
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/archives" class="menu gt-a-link">
                            归档
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/post/guan-yu/" class="menu gt-a-link">
                            关于
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/tags" class="menu gt-a-link">
                            标签
                        </a>
                    
                </div>
            
        </div>
    </div>
</nav>
    <div class="post-container">
        <div class="post-detail gt-bg-theme-color-second">
            <article class="gt-post-content">
                <h2 class="post-title">
                    docker搭建redis集群(最新修改)
                </h2>
                <div class="post-info">
                    <time class="post-time gt-c-content-color-first">
                        · 2020-04-10 ·
                    </time>
                    
                        <a href="https://lucky-zwx.github.io/tag/qU5dGWy2W/" class="post-tags">
                            # docker
                        </a>
                    
                        <a href="https://lucky-zwx.github.io/tag/oiVunfyfZ0/" class="post-tags">
                            # 运维
                        </a>
                    
                </div>
                <div class="post-content">
                    <pre><code class="language-docker">docker pull redis
# 在 /home 目录下创建redis-cluster-test 文件夹
➜ mkdir -p /home/redis-cluster-test
➜ cd  /home/redis-cluster-test
➜ vim redis-cluster.conf

# 把下列信息写入redis-cluster.conf文件中
  port ${PORT}
  cluster-enabled yes
  cluster-config-file nodes.conf
  cluster-node-timeout 5000
  appendonly yes

# 在 /home/redis-cluster-test 目录下生成conf和data目录，并生成配置文件
➜ for port in `seq 6380 6385`; do 
    mkdir -p ./${port}/conf &amp;&amp; PORT=${port} envsubst &lt; ./redis-cluster.conf &gt; ./${port}/conf/redis.conf &amp;&amp; mkdir -p ./${port}/data;
  done

# tree命令查看目录(如果命令不存在，执行安装命令：yum -y install tree)
➜ tree
.
├── 6380
│   ├── conf
│   │   └── redis.conf
│   └── data
├── 6381
│   ├── conf
│   │   └── redis.conf
│   └── data
├── 6382
│   ├── conf
│   │   └── redis.conf
│   └── data
├── 6383
│   ├── conf
│   │   └── redis.conf
│   └── data
├── 6384
│   ├── conf
│   │   └── redis.conf
│   └── data
├── 6385
│   ├── conf
│   │   └── redis.conf
│   └── data
└── redis-cluster.conf

18 directories, 7 files

# 创建6个redis容器
➜ for port in `seq 6380 6385`; do 
     docker run --net=host --name=redis-${port} -v `pwd`/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf -d redis:latest redis-server /usr/local/etc/redis/redis.conf; 
  done

# 本人使用Debian系统

➜ apt install redis

# 启动集群

➜ redis-cli --cluster create 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 --cluster-replicas 1
</code></pre>

                </div>
            </article>
        </div>

        
            <div class="next-post">
                <div class="next gt-c-content-color-first">下一篇</div>
                <a href="https://lucky-zwx.github.io/post/docker-bu-shu-golang/" class="post-title gt-a-link">
                    Docker部署Golang
                </a>
            </div>
        

        

        <div class="site-footer gt-c-content-color-first">
    <div class="slogan gt-c-content-color-first">走远路，见微光</div>
    <div class="social-container">
        
            
                <a href="https://github.com/lucky-zwx" target="_blank">
                    <i class="fab fa-github gt-c-content-color-first"></i>
                </a>
            
        
            
        
            
        
            
        
            
        
            
        
    </div>
    <div class="footer-info">
        不要再看下面了!🐷
    </div>
    <div>
        Theme by <a href="https://imhanjie.com/" target="_blank">imhanjie</a>, Powered by <a
                href="https://github.com/getgridea/gridea" target="_blank">Gridea | <a href="https://lucky-zwx.github.io/atom.xml" target="_blank">RSS</a></a>
    </div>
</div>

<script>
    hljs.initHighlightingOnLoad()
</script>


    </div>
</div>
</body>
</html>
